﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

// Token: 0x0200030C RID: 780
public class EfficientMicroNPC : MicroNPC
{
	// Token: 0x060013B9 RID: 5049 RVA: 0x00083D7C File Offset: 0x00081F7C
	protected override void Awake()
	{
		base.Awake();
		this.ConvertComponents();
	}

	// Token: 0x060013BA RID: 5050 RVA: 0x00083D8C File Offset: 0x00081F8C
	public void ConvertComponents()
	{
		this.anim.enabled = false;
		this.anim.speed = 0f;
		RigidbodyConstraints rigidbodyConstraints = this.rbody.constraints;
		rigidbodyConstraints |= RigidbodyConstraints.FreezeRotationX;
		rigidbodyConstraints |= RigidbodyConstraints.FreezeRotationZ;
		foreach (SkinnedMeshRenderer skinnedMeshRenderer in base.GetComponentsInChildren<SkinnedMeshRenderer>())
		{
			GameObject gameObject = skinnedMeshRenderer.gameObject;
			MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
			MeshRenderer meshRenderer = gameObject.AddComponent<MeshRenderer>();
			meshFilter.sharedMesh = skinnedMeshRenderer.sharedMesh;
			meshRenderer.sharedMaterials = skinnedMeshRenderer.sharedMaterials;
			UnityEngine.Object.Destroy(skinnedMeshRenderer);
		}
		UnityEngine.Object.Destroy(base.transform.GetChild(0).gameObject);
	}

	// Token: 0x060013BB RID: 5051 RVA: 0x00083E3C File Offset: 0x0008203C
	private IEnumerator deathFallRotation()
	{
		Transform modelTransform;
		if (!EfficientMicroNPC.TryGetChild(base.transform, 0, out modelTransform))
		{
			yield break;
		}
		float startTime = Time.time;
		float endTime = Time.time + this.deathAnimationDuration;
		Quaternion startRotation = modelTransform.rotation;
		Quaternion endRotation = startRotation * Quaternion.AngleAxis(-90f, Vector3.right);
		while (Time.time < endTime)
		{
			float interpolationValue = Mathf.InverseLerp(startTime, endTime, Time.time);
			modelTransform.rotation = Quaternion.Slerp(startRotation, endRotation, interpolationValue);
			yield return null;
		}
		modelTransform.rotation = endRotation;
		yield break;
	}

	// Token: 0x060013BC RID: 5052 RVA: 0x00083E58 File Offset: 0x00082058
	private static bool TryGetChild(Transform parrent, int index, out Transform output)
	{
		bool result;
		try
		{
			output = parrent.GetChild(index);
			result = true;
		}
		catch (Exception)
		{
			output = null;
			result = false;
		}
		return result;
	}

	// Token: 0x060013BD RID: 5053 RVA: 0x00002973 File Offset: 0x00000B73
	private void UNetVersion()
	{
	}

	// Token: 0x060013BE RID: 5054 RVA: 0x00083E94 File Offset: 0x00082094
	public override bool OnSerialize(NetworkWriter writer, bool forceAll)
	{
		bool flag = base.OnSerialize(writer, forceAll);
		bool flag2;
		return flag2 || flag;
	}

	// Token: 0x060013BF RID: 5055 RVA: 0x00083BF9 File Offset: 0x00081DF9
	public override void OnDeserialize(NetworkReader reader, bool initialState)
	{
		base.OnDeserialize(reader, initialState);
	}

	// Token: 0x04001706 RID: 5894
	[SerializeField]
	protected float deathAnimationDuration = 1f;
}
